package com.example.easyutils.dram;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.easyutils.R;

import java.util.List;
import java.util.Map;

public class DramRecycleView extends RecyclerView.Adapter {
    private Context context;
    private List mList;
    public DramRecycleView(Context context, List mList) {
        this.context = context;
        this.mList = mList;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.dram_item,parent,false);
        ViewHoder viewHoder = new ViewHoder(view);
        return viewHoder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
//        String contentStr = Html.fromHtml(((Map)mList.get(position)).get("content").toString());
        ((ViewHoder)holder).content.setText(Html.fromHtml(((Map)mList.get(position)).get("content").toString()));
        ((ViewHoder)holder).title.setText(Html.fromHtml(((Map)mList.get(position)).get("title").toString()));
        ((ViewHoder)holder).tip.setText(Html.fromHtml(((Map)mList.get(position)).get("type").toString()));
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ViewHoder extends RecyclerView.ViewHolder {
        private TextView content,title,tip;
        public ViewHoder(@NonNull View itemView) {
            super(itemView);
            content = itemView.findViewById(R.id.content);
            title = itemView.findViewById(R.id.title);
            tip = itemView.findViewById(R.id.tip);
        }
    }
}
